{layout name="public/layout" /}
{include file='yxnavbar'}


<div class="main">
    <ul class="nav nav-tabs">
        <li {if $ac == 'display'}class="active"{/if}><a href="{php echo createWebUrl('Lt_main',array('themeid'=>$themeid));}" >奖项列表</a></li>
        {if $page_total<6}
        <li {if $ac == 'add'}class="active"{/if}><a href="{php echo createWebUrl('Lt_main', array('ac' =>'add','themeid'=>$themeid));}" >新增奖项</a></li>
        {/if}
        {if $ac == 'edit'}<li class="active"><a href="{php echo createWebUrl('Lt_main', array('ac' =>'edit','themeid'=>$themeid));}" >奖项修改</a></li>{/if}
        <li ><a href="{php echo createWebUrl('Lt_chance', array('ac' =>'display','themeid'=>$themeid));}" >抽奖机会</a></li>
        <li ><a href="{php echo createWebUrl('Lt_winning', array('ac' =>'display','themeid'=>$themeid));}" >中奖记录</a></li>
    </ul>
    {if $ac == "display"}
    <div class="panel panel-info">
        <div class="panel-heading">当前数量： {$page_total}</div>
    </div>
    {/if}
    <input type="hidden" name="current_ac" id="current_ac" value="{$ac}">
    <input type="hidden" name="has_free" id="has_free" value="{$has_free}">
        <!--  列表框  -->
        {if $ac =='display'}
        <div class="tab-content">
            <div class="panel panel-default">
            <div class="panel-body table-responsive">
                <table class="table table-hover">
                    <thead class="navbar-inner">
                    <tr>
                        <th style="width: 50px">序号</th>
                        <th style="width: 120px">奖品图</th>
                        <th style="width: 100px">奖品</th>
                        <th style="width: 80px">奖品名称</th>
                        <th style="width: 100px">库存</th>
                        <th style="width: 120px">奖品类型</th>
                        <th style="width: 100px">中奖概率</th>
                        <th style="width: 100px">中奖记录占比</th>
                        <th style="width: 100px">展示排序</th>
                        <th style="width: 120px">领奖动作</th>
                        <th style="width: 120px">领奖动作次数</th>
                        <th style="width: 120px">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {loop $list $item}
                    <tr>
                        <td>{$item['ltt_id']}</td>
                        <td><a href="{php echo tomedia($item['ltp_img']);}"  target="_blank" title="查看原图"><img src="{php echo tomedia($item['ltp_img']);}" style="width: 40px;height: 40px;padding: 1px;"></a></td>

                        <td>{$item['ltt_title']}</td>
                        <td>{$item['ltp_name']}</td>
                        <td>{$item['ltt_qty']}</td>
                        <td>{$item_type_list[$item['it_type']]}</td>
                        <td>{php echo $item['ltt_ratiio']/100;}%</td>
                        <td>{php echo $item['ltt_showratiio']/100;}%</td>
                        <td>{$item['sort']}</td>
                        <td>{$receive_list[$item['receive_key']]}</td>
                        <td>{$item['receive_todo_num']}</td>
                        <td>
                            <a class="btn btn-primary btn-sm" style="width: 35px" onclick="changeOrDelLttInfo(this)" data-type="edit" data-edit-url="{php echo createWebUrl('Lt_main', array('ac' =>'edit','themeid'=>$themeid,'ltt_id'=>$item['ltt_id']));}" data-themeid="{$themeid}" data-id="{$item['ltt_id']}"  title="修改奖品信息" data-toggle="tooltip" data-placement="top"><i class="fa fa-pencil-square-o"> </i></a>
                            <a class="btn btn-danger btn-sm" style="width: 35px" onclick="changeOrDelLttInfo(this)" data-type="del"  data-edit-url="" data-themeid="{$themeid}" data-id="{$item['ltt_id']}" title="删除奖品" data-toggle="tooltip" data-placement="top"><i class="fa fa-times"> </i></a>
                        </td>
                    </tr>
                    {/loop}
                    </tbody>
                </table>
            </div>
        </div>
        </div>

        {/if}
        {if $ac =='add' || $ac =='edit'}
        <div class="panel panel-default" role="tabpanel">
            <div class="panel-heading">基本信息</div>
            <div class="panel-body">
                <form action="" method="post" class="form-horizontal" role="form" name="form2" id="form2">
                    <input type="hidden" name="ltt_id" value="{$item['ltt_id']}"/>
                    <input type="hidden" name="themeid" value="{$themeid}"/>

                    <div class="form-group">
                        <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>奖品</label>
                        <div class="col-sm-8 col-xs-12">
                            <input type="text" class="form-control"  placeholder="" name="ltt_title"  value="{$item['ltt_title']}">
                            <span class="help-block">显示在转盘中 示例：一等奖 </span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>奖品名称</label>
                        <div class="col-sm-8 col-xs-12">
                            <input type="text" class="form-control"  placeholder="" name="ltp_name"  value="{$item['ltp_name']}">
                            <span class="help-block">显示在中奖后的弹窗 示例：苹果12Pro 限8个字以内</span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>库存</label>
                        <div class="col-sm-8 col-xs-12">
                            <input type="number" class="form-control"  placeholder="" name="ltt_qty"  value="{$item['ltt_qty']}">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>奖品类型</label>
                        <div class="col-sm-9 col-xs-12">
                            <select id="it_type" name="it_type">
                                {loop $item_type_list $key $row}
                                <option value="{$key}" {if $item['it_type'] == $key}selected="selected"{/if}>{$key} - {$row}</option>
                                {/loop}
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>中奖概率</label>
                        <div class="col-sm-8 col-xs-12">
                            <div class="col-sm-4 col-xs-12 input-group">
                                <input class="form-control" type="number"  placeholder="" name="ltt_ratiio"  value="{php echo $item['ltt_ratiio']/100;}">
                                <span class="input-group-addon">%</span>
                            </div>
                            <span class="help-block">示例：0.01% 请填写数字 0.01</span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">中奖记录占比</label>
                        <div class="col-sm-8 col-xs-12">
                            <div class="col-sm-4 col-xs-12 input-group">
                                <input class="form-control" type="number"  placeholder="" name="ltt_showratiio"  value="{php echo $item['ltt_showratiio']/100;}">
                                <span class="input-group-addon">%</span>
                            </div>
                            <span class="help-block">小程序里中奖记录显示此奖品的比例；以及弹幕中显示的比例；示例：0.01% 请填写数字 0.01</span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>奖品展示排序</label>
                        <div class="col-sm-8 col-xs-12">
                            <div class="col-sm-4 col-xs-12 input-group">
                                <input class="form-control" type="number"  placeholder="1" maxlength="2" name="sort" id="item_sort"  value="{php echo $item['sort'];}">
                                <span class="input-group-addon">位</span>
                            </div>
                            <span class="help-block">排名靠前 数值越小 最小为1</span>
                        </div>
                    </div>
<!--                    <div class="form-group">-->
<!--                        <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>奖项别名</label>-->
<!--                        <div class="col-sm-8 col-xs-12">-->
<!--                            <input type="text" class="form-control"  placeholder="" name="ltt_other_title"  value="{$item['ltt_other_title']}">-->
<!--                            <span class="help-block">示例：超值豪华一等奖</span>-->
<!--                        </div>-->
<!--                    </div>-->
                    <div class="form-group">
                        <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>奖品小图</label>
                        <div class="col-sm-8 col-xs-12">
                            {php echo view_form_field_image('ltp_img',$item['ltp_img']);}
                            <span class="help-block">图片尺寸：200*200像素</span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">奖品详情图</label>
                        <div class="col-sm-8 col-xs-12">
                            {php echo view_form_field_multi_image('centerimgs',xunserializer($item['ltp_detail_imgs']));}
                            <span class="help-block">暂未开发</span>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">中奖后领取动作</label>
                        <div class="col-sm-9 col-xs-12">
                            <select id="receive_key_id" name="receive_key_id">
                                {loop $receive_list $key $row}
                                <option value="{$key}" {if $item['receive_key'] == $key}selected="selected"{/if}>{$key} - {$row}</option>
                                {/loop}
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">中奖后动作次数</label>
                        <div class="col-sm-8 col-xs-12">
                            <input type="number" class="form-control"  placeholder="" name="receive_todo_num"  value="{$item['receive_todo_num']}">
                        </div>
                    </div>

                    <div class="form-group" id="sub_upload" >
                        <div class="col-sm-12">
                            <input name="submit" onclick="addOrEditLtItem()" id="btnConfirm" type="button" value="提交" class="btn btn-primary col-lg-2">
                        </div>
                    </div>

                </form>
            </div>
        </div>
        {/if}
</div>

{if $ac =='display'}
{$pager}
{/if}
<script type="text/javascript">
    $(document).ready(
        function (){
            //检车后台设置未中奖奖品
            let has_free = $("#has_free").val();
            if (!has_free){
                layer.msg('后台未设置未中奖奖品');
            }
        }
    );
    function drop_confirm(msg, url){
        if(confirm(msg)){
            window.location = url;
        }
    }
    //新增\修改奖品 提交数据
    function addOrEditLtItem() {
        if ($("#item_sort").val().length>2){
            layer.msg('奖品展示排名，请设置两位数以内的排序值');
            return;
        }
        let postUrl = "{php echo createWebUrl('lt_addoreditltitem');}";
        let success_redirect = "{php echo createWebUrl('Lt_main',array('themeid'=>$themeid));}";
        let formData = $("#form2").serialize();
        $.ajax({
            url:postUrl,
            dataType:'json',
            method:'post',
            data:formData,
            success:function (e) {
                let res = e.message;
                let code = res.code;
                let msg = res.msg;
                if (code!=200){
                    layer.msg(msg)
                }else{
                    layer.msg(msg);
                    window.location.href = success_redirect;
                }

            },
            fail:function (err) {
                console.log(err)
            }
        })
    }
    // 修改、删除奖品
    function changeOrDelLttInfo(e) {
        let ltt_id = e.getAttribute("data-id");
        let type = e.getAttribute("data-type");
        let themeid = e.getAttribute("data-themeid");
        let redirectUrl = e.getAttribute("data-edit-url");
        let postUrl ="";
        if (type=='edit'){
            window.location.href = redirectUrl;
        }
        if (type=='del'){
            postUrl = "{php echo createWebUrl('lt_delltitem');}";
            layer.msg('您确定删除该奖品吗？',{
                btn:['确定','取消'],
                yes:function (index) {
                    $.ajax({
                        url:postUrl,
                        dataType:'json',
                        method:'post',
                        data: {ltt_id:ltt_id,themeid:themeid},
                        success:function (e) {
                            let res = e.message;
                            let code = res.code;
                            let msg = res.msg;
                            if (code!=200){
                                layer.msg(msg);
                            }else{
                                layer.msg(msg);
                                location.reload();
                            }
                        },
                        fail:function (err) {
                            console.log(err)
                        }
                    });
                }
            });
        }
    }
</script>
